
<div class="tzggPage">

<div class="listAll">
    <div class="content">
       <!-- <div class="imgSin">
            <a>
                <div class="Photo_left"><img src="images/file.png"/></div>
                <div class="Photo_right">
                    <span class="wordSin">的风范热的风范热的风范热的风范热的风范热</span>
                    <img class="imgCheck" src="images/noselect.png">
                    <div style="color: #9d9d9d">
                        <span style="width: 70%;display: inline-block; margin-left: 8px;">漳卅</span>
                        <span>2017/01/10</span>
                    </div>
                </div>
            </a>
        </div>-->
    </div>
</div>

<div class="btnChoose">
    <div id="returnIndex">
        <img src="images/return.png" style="width: 25px;padding-top: 8px;"><br>
        <span>返回</span>
    </div>
    <div>
        <img src="images/add.png" id="addNew" style="width: 66px;position: relative;top: -12px;">
    </div>
    <div id="delete">
        <img src="images/delete.png" style="width: 20px;padding-top: 8px;"><br>
        <span>删除</span>
    </div>
</div>

<div class="weui_dialog_alert" style="display: none;">
    <div class="weui_mask"></div>
    <div class="weui_dialog">
        <div class="weui_dialog_hd"> <strong class="weui_dialog_title">警告</strong>
        </div>
        <div class="weui_dialog_bd">弹窗内容，告知当前页面信息等</div>
        <div class="weui_dialog_ft">
            <a href="javascript:;" class="weui_btn_dialog primary">确定</a>
        </div>
    </div>
</div>

<script>
    $(function(){
        // 页数
        var page = 0;
        // 每页展示5个
        var size = 10;

        // dropload
        $('.listAll').dropload({
            scrollArea : window,
            loadDownFn : function(me){
                page++;
                // 拼接HTML
                var result = '';
                $.ajax({
                    type: 'GET',
                    url: path + '/api/weixin/getNoticeList?page='+page+'&size='+size+'&token='+window.localStorage.getItem("token"),
                    dataType: 'json',
                    success: function(data){
                        if(data.code == 501){
                            window.location.href = "login.html";
                            return;
                        }
                        var arrLen = data.schoolNoticeEntity.length;
                        if(arrLen > 0){
                                for(var i=0; i<arrLen; i++){
                                    result += '<div class="imgSin"> <a><div class="Photo_left"><img src="images/file.png"/></div><div class="Photo_right"> <span class="wordSin" title="'+ data.schoolNoticeEntity[i].id +'">'+
                                            data.schoolNoticeEntity[i].title +'</span>' +
                                            '<img class="imgCheck" src="images/noselect.png" title="'+ data.schoolNoticeEntity[i].id +'"> <div style="color: #9d9d9d">' +
                                            ' <span style="width: 70%;display: inline-block; margin-left: 8px;">'+ data.schoolNoticeEntity[i].createBy +'</span><span>'+
                                            data.schoolNoticeEntity[i].gmtCreate.substr(0,10) +'</span></div> </div></a></div>';
                                }
                        }else{
                            // 如果没有数据
                            // 锁定
                            me.lock();
                            // 无数据
                            me.noData();
                        }
                        // 插入数据到页面，放到最后面
                        $('.content').append(result);
                        // 每次数据插入，必须重置
                        me.resetload();
                    },
                    error: function(xhr, type){
                        // 即使加载出错，也得重置
                        me.resetload();
                    }
                });
            }
        });
    });
    $.weui = {};
    $.weui.alert = function(options,sureEvent){
        options = $.extend({title: '提示', text: '提示内容'}, options);
        var $alert = $('.weui_dialog_alert');
        $alert.find('.weui_dialog_title').text(options.title);
        $alert.find('.weui_dialog_bd').text(options.text);
        $alert.on('touchend click', '.weui_btn_dialog', function(event){
            $alert.hide();
            if(sureEvent){
                sureEvent();
            }
            //阻止事件冒泡
            // event.stopPropagation();
            return false;
        });
        $(".weui_mask").click(function(){
            $alert.hide();
        });
        $alert.show();
    };


    var deleList = [];
    $(".content").on('click','.imgCheck',function(){
        if($(this).attr("src").indexOf("selected")>0){
            $(this).attr("src","images/noselect.png");
        }else {
            $(this).attr("src","images/selected.png");
        }
    });
    $(".content").on('click','.wordSin',function(){
        window.location.href = "tzggDetail.html?id=" + $(this).attr("title");
    });

    $("#delete").click(function(){
        for(var i = 0;i< $(".imgCheck").length ; i++ ){
            if($(".imgCheck").eq(i).attr("src").indexOf("selected")>0){
                deleList.push($(".imgCheck").eq(i).attr("title"));
            }
        }
        if(deleList.length == 0){
            $.weui.alert({text: "请选择要删除的数据！"});
        }else{
            $.weui.alert({text: "确定删除吗?"},function(){
                //删除数据
                $.ajax({
                    type : "POST",
                    url : path + "/api/weixin/deleteNotice",//?token=" + window.localStorage.getItem("token"),
                    data : {
                        "token" : window.localStorage.getItem("token"),
                        "ids" : JSON.stringify(deleList)
                    },
                    dataType : 'json',
                    success : function(msg) {
                        if(msg.code == 0){
                            window.location.href = "tzggList.html?pageIndex=2";
                        }else if(msg.code == 501){
                            window.location.href = "login.html";
                        }
                    }
                })
            });
        }
    });

    $("#returnIndex").click(function(){
        window.location.href = "index.html";
    });
    $("#addNew").click(function(){
        window.location.href = "tzgg.html";
    });

</script>
</div>
